import { defineStore } from 'pinia'
import tool from '../utils/tool.js';

// 先默认二级菜单，后期再考虑优化多级菜单
export const usebreadCrumbStore = defineStore('breadCrumb', {
    state() {
        return {
            firstBreadCrumb: '系统设置',
            firstBreadCrumbPath: '/layout/setting/project',
            firstBreadCrumbIcon: 'shezhi-1',
            secondBreadCrumb: '系统管理',
            secondBreadCrumbPath: '/layout/setting/xtgl',
            secondBreadCrumbIcon: 'yonghu-1'
        }
    },
    actions: {
        // 设置一级面包屑
        setFirstBreadCrumb(title: string, path: string, icon: string) {
            this.firstBreadCrumb = title;
            this.firstBreadCrumbPath = path;
            this.firstBreadCrumbIcon = icon;
            this.saveToLocalStorage();
        },
        // 设置二级面包屑
        setSecondBreadCrumb(title: string, path: string, icon: string) {
            this.secondBreadCrumb = title;
            this.secondBreadCrumbPath = path;
            this.secondBreadCrumbIcon = icon;
            this.saveToLocalStorage();
        },
        //  加载状态
        loadFromLocalStorage() {
            const stateData = tool.data.get('breadCrumbState');
            if (stateData) {
                const parseData = JSON.parse(stateData);
                Object.assign(this, parseData)
            }
        },
        // 保存
        saveToLocalStorage() {
            tool.data.set('breadCrumbState', JSON.stringify(this.$state));
        }
    }
})
// console.log(usebreadCrumbStore());

// usebreadCrumbStore().loadFromLocalStorage()